<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
  <script type="text/javascript">
      var selectIconId = null;
  </script>
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <div class="row h-home-path">
          <div class="col-md-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">编辑资源信息</li>
            </ol>
          </div>
        </div>
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" id="return-btn" onclick="returnIndex()"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>返回
              </button>
              <button class="btn btn-info" id="save" onclick="ResourceMgr.submitForm()" type="button"><i
                      class="fa fa-save">&nbsp;&nbsp;</i>保存
              </button>
            </div>
          </form>
        </div>

        <div class="form-horizontal  h-form-warp">
          <div class="h-msg-title h-table-header">
            <strong>资源信息</strong>
          </div>
          <form action="/securityResource/saveResource" class="form-horizontal" id="resourceForm" method="post"
                role="form">
            <input id="operation" name="operation" type="hidden" value="${operation!}"/>
            <input class="form-control" id="id" name="id" type="hidden" value="${securityResource.id!}"/>
            <input class="form-control" id="parentId" name="parentId" type="hidden"
                   value="${securityResource.parentId!}"/>
            <input class="form-control" id="btnAuthInfo" name="btnAuthInfo" type="hidden" value=""/>
            <div class="form-group">
              <label class="col-sm-2 control-label">父资源：</label>
              <div class="col-sm-8">
                <input class="form-control" id="parentName" name="parentName" readonly="readonly"
                       required="required" type="text" value="${securityResource.parentName!}"/>
              </div>
              <div class="col-sm-1">
                <input class="btn btn-info" id="selectParentResource" onclick="ResourceMgr.selectParentResource()"
                       type="button"
                       value="选择"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">资源名称：</label>
              <div class="col-sm-8">
                <input class="form-control" id="resName" name="resName" required="required" type="text"
                       value="${securityResource.resName!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">资源URL：</label>
              <div class="col-sm-8">
                <input class="form-control" id="resUrl" name="resUrl" required="required" type="text"
                       value="${securityResource.resUrl!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">资源图标：</label>
              <div class="col-sm-8">
                <input class="form-control" id="resIcon" name="resIcon" onclick="ResourceMgr.showIcon(this)"
                       readonly="readonly"
                       type="text" value="${securityResource.resIcon!}"/>
              </div>
            </div>
            <#include "/system/systemIcon_select.html">
            <div class="form-group">
              <@PageDict dict_name="needAuth" dict_desc="是否需要权限校验" dict_key="std_zb_yn"
              dict_value="${securityResource.needAuth!}"
              dict_type="select" label_class="col-sm-2 control-label text-right" dict_class="col-sm-8"
              required="required" default_value="N"/>
            </div>
            <div class="form-group">
              <@PageDict dict_name="isView" dict_desc="是否可见" dict_key="std_zb_yn"
              dict_value="${securityResource.isView!}"
              dict_type="select" label_class="col-sm-2 control-label text-right" dict_class="col-sm-8"
              required="required" default_value="Y"/>
            </div>
            <div class="form-group">
              <@PageDict dict_name="isMenu" dict_desc="是否菜单" dict_key="std_zb_yn"
              dict_value="${securityResource.isMenu!}"
              dict_type="select" label_class="col-sm-2 control-label text-right" dict_class="col-sm-8"
              required="required" default_value="Y"/>
            </div>
            <#if securityResource.isMenu='Y'>
            <div class="form-group">
              <@PageDict dict_name="btnList" dict_desc="按钮权限" dict_key="button_type"
              dict_value="${securityResource.btnList!}"
              dict_type="checkbox" label_class="col-sm-2 control-label text-right" dict_class="col-sm-8"
              required="false" dict_method="ResourceMgr.showBtnAuth()"/>
            </div>
            <div id="btnListDiv" style="display:none">
              <div class="form-group">
                <div id="addCodeDiv" style="display:none">
                  <label class="col-sm-2 control-label">新增按钮权限编码：</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="addResUrl" name="addResUrl" placeholder="xx:xx:add" type="text"
                           value=""/>
                  </div>
                </div>
                <div id="editCodeDiv" style="display:none">
                  <label class="col-sm-2 control-label">修改按钮权限编码：</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="editResUrl" name="editResUrl" placeholder="xx:xx:edit" type="text"
                           value=""/>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <div id="delCodeDiv" style="display:none">
                  <label class="col-sm-2 control-label">删除按钮权限编码：</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="delResUrl" name="delResUrl" placeholder="xx:xx:del" type="text"
                           value=""/>
                  </div>
                </div>
                <div id="viewCodeDiv" style="display:none">
                  <label class="col-sm-2 control-label">查看按钮权限编码：</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="viewResUrl" name="viewResUrl" placeholder="xx:xx:view" type="text"
                           value=""/>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <div id="saveCodeDiv" style="display:none">
                  <label class="col-sm-2 control-label">保存按钮权限编码：</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="saveResUrl" name="saveResUrl" placeholder="xx:xx:save" type="text"
                           value=""/>
                  </div>
                </div>
                <div id="submitCodeDiv" style="display:none">
                  <label class="col-sm-2 control-label">提交按钮权限编码：</label>
                  <div class="col-sm-3">
                    <input class="form-control" id="submitResUrl" name="submitResUrl" placeholder="xx:xx:submit"
                           type="text" value=""/>
                  </div>
                </div>
              </div>
            </div>
          </#if>
          <div class="form-group">
            <label class="col-sm-2 control-label">资源顺序：</label>
            <div class="col-sm-8">
              <input class="form-control" digits="true" id="resOrder" name="resOrder"
                     type="text"
                     value="${securityResource.resOrder!}"/>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">说明：</label>
            <div class="col-sm-8">
              <input class="form-control" id="comment" name="comment" required="required" type="text"
                     value="${securityResource.comment!}"/>
            </div>
            <div class="col-sm-1">
              <span class="required">*</span>
            </div>
          </div>
          </form>
        </div>
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->
</div>

<#include "/common/jslib.html">
<!-- 弹窗下拉 -->
<script type="text/javascript">
    function returnIndex() {
        window.location.href = "/securityResource/index";
    }

    $(function () {
        // 页面操作类型：add(添加)-edit(编辑)-view(查看)
        var operation = $("#operation").val();
        // 弹出窗体控制
        ResourceMgr = {
            // 初始化
            init: function () {
                // 查看的时候不显示保存按钮
                if (operation == "view") {
                    Jmts.setFormReadOnly();
                }
                //控制显示按钮权限信息
                var btnAuthInfo = "${securityResource.btnAuthInfo!}";
                if (!Jmts.isEmpty(btnAuthInfo)) {
                    $("#btnListDiv").show();
                    var btnList = btnAuthInfo.split(",");
                    if (!Jmts.isEmpty(btnList) && btnList.length > 0) {
                        for (var i = 0; i < btnList.length; i++) {
                            var btnInfo = btnList[i].split("##");
                            var btnCode = btnInfo[0];
                            var btnUrl = btnInfo[1];
                            if (btnCode == "add") {
                                $("#addResUrl").val(btnUrl);
                                $("#addCodeDiv").show();
                            } else if (btnCode == "edit") {
                                $("#editResUrl").val(btnUrl);
                                $("#editCodeDiv").show();
                            } else if (btnCode == "view") {
                                $("#viewResUrl").val(btnUrl);
                                $("#viewCodeDiv").show();
                            } else if (btnCode == "delete") {
                                $("#delResUrl").val(btnUrl);
                                $("#delCodeDiv").show();
                            } else if (btnCode == "save") {
                                $("#saveResUrl").val(btnUrl);
                                $("#saveCodeDiv").show();
                            } else if (btnCode == "submit") {
                                $("#submitResUrl").val(btnUrl);
                                $("#submitCodeDiv").show();
                            }
                        }
                    }
                }
            },
            // init end

            // 提交数据
            submitForm: function () {
                //处理按钮权限信息
                var checkSuccess = ResourceMgr.initBtnAuthInfo();
                if (!checkSuccess) {
                    return false;
                }
                Jmts.ajaxSubmit(document.getElementById("resourceForm"), function (result) {
                    if (result.success) {
                        if (operation == 'add') {
                            ResourceMgr.returnIndex();
                        } else {
                            Jmts.succTips(result.msg);
                            window.location.reload();
                        }
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                });
                return false;
            },
            // submitForm end
            returnIndex: function () {
                window.location.href = "/securityResource/index";
            },
            selectParentResource: function () {
                var id = $("#id").val();
                var url = "/securityResource/selectParentResource?id=" + id +
                    "&selectType=single?returnMethod=ResourceMgr.initParentResource";
                Jmts.openDialog("parentMenu", url, "选择父级菜单", 500, 700, 32);
            },
            showIcon: function (obj) {
                selectIconId = $(obj).attr("id");
                $("#selectResIcon").show();
            },
            initBtnAuthInfo: function () {
                var btnAuthInfo = [];
                var btnList = [];
                $('input[name="btnList"]:checked').each(function () {
                    btnList.push($(this).val());
                });
                for (var i in btnList) {
                    var btnCode = btnList[i];
                    if (btnCode == "add") {
                        if (Jmts.isEmpty($("#addResUrl").val())) {
                            Jmts.alert("新增按钮权限编码不能为空");
                            return false;
                        }
                        btnAuthInfo.push(btnCode + "##" + $("#addResUrl").val());
                    } else if (btnCode == "edit") {
                        if (Jmts.isEmpty($("#editResUrl").val())) {
                            Jmts.alert("修改按钮权限编码不能为空");
                            return false;
                        }
                        btnAuthInfo.push(btnCode + "##" + $("#editResUrl").val());
                    } else if (btnCode == "view") {
                        if (Jmts.isEmpty($("#viewResUrl").val())) {
                            Jmts.alert("查看按钮权限编码不能为空");
                            return false;
                        }
                        btnAuthInfo.push(btnCode + "##" + $("#viewResUrl").val());
                    } else if (btnCode == "delete") {
                        if (Jmts.isEmpty($("#delResUrl").val())) {
                            Jmts.alert("删除按钮权限编码不能为空");
                            return false;
                        }
                        btnAuthInfo.push(btnCode + "##" + $("#delResUrl").val());
                    } else if (btnCode == "save") {
                        if (Jmts.isEmpty($("#saveResUrl").val())) {
                            Jmts.alert("保存按钮权限编码不能为空");
                            return false;
                        }
                        btnAuthInfo.push(btnCode + "##" + $("#saveResUrl").val());
                    } else if (btnCode == "submit") {
                        if (Jmts.isEmpty($("#submitResUrl").val())) {
                            Jmts.alert("提交按钮权限编码不能为空");
                            return false;
                        }
                        btnAuthInfo.push(btnCode + "##" + $("#submitResUrl").val());
                    }
                }
                $("#btnAuthInfo").val(btnAuthInfo.join(","));
                return true;
            },
            showBtnAuth: function () {
                var allBtnList = ["add", "edit", "del", "view", "save", "submit"];
                var btnList = [];
                $('input[name="btnList"]:checked').each(function () {
                    btnList.push($(this).val());
                });
                //控制按钮权限编码显示
                if (btnList != null && btnList.length > 0) {
                    $("#btnListDiv").show();
                    for (var i in btnList) {
                        var btnCode = btnList[i];
                        if (btnCode == "add") {
                            $("#addCodeDiv").show();
                        } else if (btnCode == "edit") {
                            $("#editCodeDiv").show();
                        } else if (btnCode == "view") {
                            $("#viewCodeDiv").show();
                        } else if (btnCode == "delete") {
                            $("#delCodeDiv").show();
                        } else if (btnCode == "save") {
                            $("#saveCodeDiv").show();
                        } else if (btnCode == "submit") {
                            $("#submitCodeDiv").show();
                        }
                    }
                } else {
                    $("#btnListDiv").hide();
                    $("#addResUrl").val("");
                    $("#editResUrl").val("");
                    $("#delResUrl").val("");
                    $("#saveResUrl").val("");
                    $("#viewResUrl").val("");
                    $("#submitResUrl").val("");
                }
                //控制没有勾选的安全权限进行隐藏处理
                for (var i in allBtnList) {
                    var btnCode = allBtnList[i];
                    if ($.inArray(btnCode, btnList) == -1) {
                        if (btnCode == "add") {
                            $("#addCodeDiv").hide();
                            $("#addResUrl").val("");
                        } else if (btnCode == "edit") {
                            $("#editCodeDiv").hide();
                            $("#editResUrl").val("");
                        } else if (btnCode == "view") {
                            $("#viewCodeDiv").hide();
                            $("#viewResUrl").val("");
                        } else if (btnCode == "delete") {
                            $("#delCodeDiv").hide();
                            $("#delResUrl").val("");
                        } else if (btnCode == "save") {
                            $("#saveCodeDiv").hide();
                            $("#saveResUrl").val("");
                        } else if (btnCode == "submit") {
                            $("#submitCodeDiv").hide();
                            $("#submitResUrl").val("");
                        }
                    }
                }
            },
            initParentResource : function(data){
                var resourceInfo = data.split("#");
                var resourceId = resourceInfo[0];
                var resourceName = resourceInfo[1];
                $("#parentId").val(resourceId);
                $("#parentName").val(resourceName);
            }
        };
        // 执行初始化
        ResourceMgr.init();
        // 前台验证表单
        $("#resourceForm").validate();
    });
</script>
</body>
</html>
